<!DOCTYPE html>
<html>
<head>
    <meta charset='UTF-8'>
    <title>天气案例</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <h2>今天天气{{info}}</h2>
        <!-- @xxx="yyy" yyy可以写一些简单的语句 -->
        <!-- <button @click="isHot = !isHot">切换天气</button> -->
        <button @click="changeWeather">切换天气</button>
        <hr/>
        <h3>a的值为{{numbers.a}}</h3>
        <button @click="numbers.a++">点击让a++</button>
        <h3>b的值为{{numbers.b}}</h3>
        <button @click="numbers.b++">点击让b++</button>
        <button @click="numbers={a:9,b:99}">替换numbers</button>
    </div>
</body>
<!--   JS   -->
    <script>
        const vm = new Vue({
            el:'#root',
            data:{
                isHot:true,
                numbers:{
                    a:1,
                    b:1
                }
            },
            computed:{
                info(){
                    return this.isHot?'炎热':'凉爽'
                }
            },
            methods: {
                changeWeather(){
                     this.isHot = !this.isHot
                }
            },
            watch:{
                isHot:{
                    //immediate:true,//初始化时调用handler
                    //isHot发生改变时
                    handler(newValue,oldValue){
                        console.log('ishot修改了',newValue,oldValue)
                    }
                },
                // 'numbers.a':{
                //     handler(){
                //         console.log('a改变了')
                //     }
                // },
                //vue监视的是numbers是否变化，不看内部是否变化，ab的地址是不发生改变的
                numbers:{
                    deep:true,//深度监视，监视多级结构中所有属性的变化
                    handler(){
                        console.log('number改变了')
                    }
                }
            }
        })
        
    </script>
</html>